<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let count = ref(0);
      console.log(count, "count");
      console.log(count.value, "count.value");
      count.value = 1;
      console.log(count.value, "count.value");

      /*
         如果ref接受的是基本类型值,原理如下(其实和vue2一样是数据劫持)
       */
      function updateDOM() {
        console.log("视图更新");
      }
      function ref(value) {
        const remImpl = {};
        Object.defineProperty(remImpl, "value", {
          get() {
            return value;
          },
          set(newVal) {
            value = newVal;
            updateDOM();
          },
        });
        return remImpl;
      }
    </script>
  </body>
</html>
